package com.mindcraft.shop.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mindcraft.base.model.MindCraftResult;
import com.mindcraft.shop.po.Category;
import com.mindcraft.shop.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "shop", tags = "商城发布接口")
@RestController
@RequestMapping("/shop/publish")
public class PublishController {

    @Autowired
    private CategoryService categoryService;


    @ApiOperation("拿到分类树")
    @GetMapping("getCategoryAllTree")
    public MindCraftResult getCategoryAllTree() {
        return categoryService.getCategoryAllTree();
    }


    @ApiOperation("拿到所有一级分类")
    @GetMapping("getOneCategory")
    public MindCraftResult getOneCategory() {
        return MindCraftResult.success(categoryService.list(new LambdaQueryWrapper<Category>().eq(Category::getParentId, 0)));
    }

    @ApiOperation("根据父级id查询所有子分类")
    @GetMapping("getCategoryList/{categoryId}")
    public MindCraftResult getCategorytList(@PathVariable("categoryId") Long id) {

        return MindCraftResult.success(categoryService.queryTreeNodes(id));
    }




}
